const config = require('./config');
const request = require('request');
const spider = require('./spider');
const message = require('./message');

const getContent = async () => {
  const content = await spider();
  const requestData = message.FeedCard(
    content.segmentfault.slice(0, 2).concat(content.juejin.slice(0, 2))
  );

  request({
    url: config.DING_URL,
    method: "POST",
    headers: { "content-type": "application/json;charset=utf-8" },
    body: JSON.stringify(requestData)
  }, function(error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log('send success');
    }
  });
}

module.exports = getContent;
